package org.vestbjergbyggecenter.Model;

import java.util.ArrayList;

public class EmployeeRecords {
	private ArrayList<Employee> employees;
	private static EmployeeRecords instance=null;
	
	//constructor
	private EmployeeRecords()
	{
		employees=new ArrayList<>();
	}
	
	//Method for the instance creation.
	public static EmployeeRecords getInstance()
	{
		if(instance==null)
		{
			instance=new EmployeeRecords();
		}
		return instance;
	}
	
	public ArrayList<Employee> getEmployees()
	{
		return employees;
	}
	
	//Method to view the elements of the employees Array List
	public void viewEmployeeList()
	{
		int size=employees.size();
		System.out.println("Employee list:");
		for (int i=0; i<size; i++)
		{
			System.out.println(" ");
			System.out.println("Employee ID: " + employees.get(i).getEmployeeID() + " " + "Employee username: " + employees.get(i).getUsername() + " " + "Eployee password: " + employees.get(i).getPassword() + " " + "Employee salary:"+ employees.get(i).getSalary());
		}
	}
	
	/*
	 * Method checks if an employee is in the employee Array List and returns it.
	 * id based
	 */
	public Employee getEmployee(int id)
	{
		Employee wantedEmployee=null;
		for(Employee employee:employees)
		{
			if(employee.getEmployeeID()==id)
			{
				wantedEmployee=employee;
			}			
		}
		if(wantedEmployee==null)
		{
			System.out.println("There is no employee by this ID.");
		}
		return wantedEmployee;
	}	
	
	/*
	 * Method to add an employee to the employee Array List
	 * Employees added from the system.
	 */
	public void addEmployee(Employee employee)
	{
		employees.add(employee);
	}	
	
	/*
	 * Method removes an employee from the employee Array List.
	 * id based
	 */
	public void removeEmployeeId(int id)
	{
		if(getEmployee(id)!=null)
		{
			employees.remove(getEmployee(id));
		}
	}
	
	/*
	 * Method updates customer.
	 * Id based.
	 */
	public void updateEmployee(int id, String newUsername, String newPassword, int newSalary)
	{
		Employee changeEmployee=getEmployee(id);
		if(changeEmployee!=null)
			{
				changeEmployee.setPassword(newPassword);
				changeEmployee.setSalary(newSalary);
				changeEmployee.setUsername(newUsername);
			}
	}
}
